<!DOCTYPE html>
<html>
<head>
  <title>HostReactor.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/vipserver/client/core/HostReactor.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.vipserver.client.core;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import com.taobao.igraph.vipserver.client.cache.DiskCache;
import com.taobao.igraph.vipserver.client.net.VIPServerProxy;
import com.taobao.igraph.vipserver.client.utils.UtilAndComs;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>/**
 * Innovated By: Xuanyin.zy@taobao.com
 * &lt;p/>
 * 2014-16-04 19:58
 */</div><span>/*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>28</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class HostReactor {</pre></td>
    </tr>
    <tr>
      <td class='line'>29</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static final long DEFAULT_DELAY = 1000L;</pre></td>
    </tr>
    <tr>
      <td class='line'>30</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static final Map&lt;String, ScheduledFuture&lt;?>> futureMap = new HashMap&lt;String, ScheduledFuture&lt;?>>();</pre></td>
    </tr>
    <tr>
      <td class='line'>31</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static Map&lt;String, Domain> domMap = new ConcurrentHashMap&lt;String, Domain>(DiskCache.read());</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static PushRecver pushRecver = new PushRecver();</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {</pre></td>
    </tr>
    <tr>
      <td class='line'>34</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        @Override</pre></td>
    </tr>
    <tr>
      <td class='line'>35</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        public Thread newThread(Runnable r) {</pre></td>
    </tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Thread thread = new Thread(r, "com.vipserver.client.updater");</pre></td>
    </tr>
    <tr>
      <td class='line'>37</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            thread.setDaemon(true);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return thread;</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>41</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    });</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static Map&lt;String, Domain> getDomMap() {</pre></td>
    </tr>
    <tr>
      <td class='line'>44</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return domMap;</pre></td>
    </tr>
    <tr>
      <td class='line'>45</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>47</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public synchronized static ScheduledFuture&lt;?> addTask(UpdateTask task) {</pre></td>
    </tr>
    <tr>
      <td class='line'>48</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return executor.schedule(task, DEFAULT_DELAY, TimeUnit.MILLISECONDS);</pre></td>
    </tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>51</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static Domain processDomJSON(String json) {</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        Domain domObj = UtilAndComs.GSON.fromJson(json, Domain.class);</pre></td>
    </tr>
    <tr>
      <td class='line'>53</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        Domain oldDom = domMap.get(domObj.getKey());</pre></td>
    </tr>
    <tr>
      <td class='line'>54</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (domObj.getHosts() == null || !domObj.validate()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>55</td><td>&nbsp;</td>
      <td><pre class='comment'>            //empty or error push, just ignore</pre></td>
    </tr>
    <tr>
      <td class='line'>56</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return oldDom;</pre></td>
    </tr>
    <tr>
      <td class='line'>57</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>59</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (oldDom != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>60</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (oldDom.getLastRefTime() > domObj.getLastRefTime()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>61</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                VIPClient.LOG.warn("out of date data received, old-t: " + oldDom.getLastRefTime()</pre></td>
    </tr>
    <tr>
      <td class='line'>62</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + ", new-t: " + domObj.getLastRefTime());</pre></td>
    </tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>65</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            domMap.put(domObj.getKey(), domObj);</pre></td>
    </tr>
    <tr>
      <td class='line'>66</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            DiskCache.write(domObj);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Map&lt;String, Host> oldHostMap = new HashMap&lt;String, Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (Host host : oldDom.getHosts()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>70</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                oldHostMap.put(host.toInetAddr(), host);</pre></td>
    </tr>
    <tr>
      <td class='line'>71</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>73</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Map&lt;String, Host> newHostMap = new HashMap&lt;String, Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (Host host : domObj.getHosts()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                newHostMap.put(host.toInetAddr(), host);</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>78</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Set&lt;Host> modHosts = new HashSet&lt;Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Set&lt;Host> newHosts = new HashSet&lt;Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>80</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Set&lt;Host> remvHosts = new HashSet&lt;Host>();</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>82</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (Host host : (List&lt;Host>)CollectionUtils.subtract(domObj.getHosts(), oldDom.getHosts())) {</pre></td>
    </tr>
    <tr>
      <td class='line'>83</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                if (oldHostMap.containsKey(host.toInetAddr())) {</pre></td>
    </tr>
    <tr>
      <td class='line'>84</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    modHosts.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>86</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    newHosts.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>87</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                }</pre></td>
    </tr>
    <tr>
      <td class='line'>88</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>90</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (Host host : (List&lt;Host>)CollectionUtils.subtract(oldDom.getHosts(), domObj.getHosts())) {</pre></td>
    </tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                if (newHostMap.containsKey(host.toInetAddr())) {</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td>&nbsp;</td>
      <td><pre class='comment'>                    // do nothing</pre></td>
    </tr>
    <tr>
      <td class='line'>93</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>94</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    remvHosts.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                }</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>98</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (newHosts.size() > 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>99</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                VIPClient.LOG.info("new ips(" + newHosts.size() + ") dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + domObj.getName() + " -> " + ArrayUtils.toString(newHosts));</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>103</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (remvHosts.size() > 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                VIPClient.LOG.info("removed ips(" + remvHosts.size() + ") dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + domObj.getName() + " -> " + ArrayUtils.toString(remvHosts));</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>108</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (modHosts.size() > 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                VIPClient.LOG.info("modified ips(" + modHosts.size() + ") dom: "</pre></td>
    </tr>
    <tr>
      <td class='line'>110</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + domObj.getName() + " -> " + ArrayUtils.toString(modHosts));</pre></td>
    </tr>
    <tr>
      <td class='line'>111</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (newHosts.size() > 0 || remvHosts.size() > 0 || modHosts.size() > 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>114</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                EventDispatcher.domChanged(domObj);</pre></td>
    </tr>
    <tr>
      <td class='line'>115</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>116</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>117</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            VIPClient.LOG.info("new ips(" + domObj.ipCount() + ") dom: " + domObj.getName() + " -> " + ArrayUtils.toString(domObj.getHosts()));</pre></td>
    </tr>
    <tr>
      <td class='line'>118</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            EventDispatcher.domChanged(domObj);</pre></td>
    </tr>
    <tr>
      <td class='line'>119</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>121</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return domObj;</pre></td>
    </tr>
    <tr>
      <td class='line'>122</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>124</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static Domain getDom(String dom, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>125</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        Domain domObj = domMap.get(Domain.getKey(dom, clusters));</pre></td>
    </tr>
    <tr>
      <td class='line'>126</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (null == domObj) {</pre></td>
    </tr>
    <tr>
      <td class='line'>127</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            domObj = new Domain(dom, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>128</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            domMap.put(domObj.getKey(), domObj);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            updateDomNow(dom, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>131</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        scheduleUpdateIfAbsent(dom, clusters);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>135</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return domMap.get(Domain.getKey(dom, clusters));</pre></td>
    </tr>
    <tr>
      <td class='line'>136</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>138</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void scheduleUpdateIfAbsent(String dom, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (futureMap.get(Domain.getKey(dom, clusters)) != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return;</pre></td>
    </tr>
    <tr>
      <td class='line'>141</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>143</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        synchronized (futureMap) {</pre></td>
    </tr>
    <tr>
      <td class='line'>144</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (futureMap.get(Domain.getKey(dom, clusters)) != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                return;</pre></td>
    </tr>
    <tr>
      <td class='line'>146</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>148</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ScheduledFuture&lt;?> future = HostReactor.addTask(new UpdateTask(dom, clusters));</pre></td>
    </tr>
    <tr>
      <td class='line'>149</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            futureMap.put(Domain.getKey(dom, clusters), future);</pre></td>
    </tr>
    <tr>
      <td class='line'>150</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>151</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>153</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void updateDomNow(String dom, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>154</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>155</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Map&lt;String, String> params = new HashMap&lt;String, String>();</pre></td>
    </tr>
    <tr>
      <td class='line'>156</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("dom", dom);</pre></td>
    </tr>
    <tr>
      <td class='line'>157</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("clusters", clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>158</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("udpPort", String.valueOf(pushRecver.getUDPPort()));</pre></td>
    </tr>
    <tr>
      <td class='line'>159</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("qps", String.valueOf(MotionFlow.view(dom)));</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>161</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Domain oldDom = getDom(dom, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>162</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (oldDom != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>163</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                params.put("checksum", oldDom.getChecksum());</pre></td>
    </tr>
    <tr>
      <td class='line'>164</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>166</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            String result = VIPServerProxy.reqAPI("srvIPXT", params);</pre></td>
    </tr>
    <tr>
      <td class='line'>167</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (StringUtils.isNotEmpty(result)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>168</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                processDomJSON(result);</pre></td>
    </tr>
    <tr>
      <td class='line'>169</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>171</td><td>&nbsp;</td>
      <td><pre class='comment'>            //else nothing has changed</pre></td>
    </tr>
    <tr>
      <td class='line'>172</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } catch (Exception e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>173</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            VIPClient.LOG.error("failed to update dom: " + dom, e);</pre></td>
    </tr>
    <tr>
      <td class='line'>174</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>175</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>177</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static void refreshOnly(String dom, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>178</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>179</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Map&lt;String, String> params = new HashMap&lt;String, String>();</pre></td>
    </tr>
    <tr>
      <td class='line'>180</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("dom", dom);</pre></td>
    </tr>
    <tr>
      <td class='line'>181</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("clusters", clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>182</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            params.put("udpPort", String.valueOf(pushRecver.getUDPPort()));</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>184</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            VIPServerProxy.reqAPI("srvIPXT", params);</pre></td>
    </tr>
    <tr>
      <td class='line'>185</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } catch (Exception e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>186</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            VIPClient.LOG.error("failed to update dom: " + dom, e);</pre></td>
    </tr>
    <tr>
      <td class='line'>187</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>188</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>191</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static class UpdateTask implements Runnable {</pre></td>
    </tr>
    <tr>
      <td class='line'>192</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        long lastRefTime = Long.MAX_VALUE;</pre></td>
    </tr>
    <tr>
      <td class='line'>193</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        private String clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>194</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        private String dom;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>196</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        public UpdateTask(String dom, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>197</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            this.dom = dom;</pre></td>
    </tr>
    <tr>
      <td class='line'>198</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            this.clusters = clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>199</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>201</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        @Override</pre></td>
    </tr>
    <tr>
      <td class='line'>202</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        public void run() {</pre></td>
    </tr>
    <tr>
      <td class='line'>203</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            Domain domObj = domMap.get(Domain.getKey(dom, clusters));</pre></td>
    </tr>
    <tr>
      <td class='line'>204</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (domObj == null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>205</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                updateDomNow(dom, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>206</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                executor.schedule(this, DEFAULT_DELAY, TimeUnit.MILLISECONDS);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>208</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                return;</pre></td>
    </tr>
    <tr>
      <td class='line'>209</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>211</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (domObj.getLastRefTime() &lt;= lastRefTime) {</pre></td>
    </tr>
    <tr>
      <td class='line'>212</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                updateDomNow(dom, clusters);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>214</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                domObj = domMap.get(Domain.getKey(dom, clusters));</pre></td>
    </tr>
    <tr>
      <td class='line'>215</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>216</td><td>&nbsp;</td>
      <td><pre class='comment'>                // if dom already updated by push, we should not override it</pre></td>
    </tr>
    <tr>
      <td class='line'>217</td><td>&nbsp;</td>
      <td><pre class='comment'>                // since the push data may be different from pull through force push</pre></td>
    </tr>
    <tr>
      <td class='line'>218</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                refreshOnly(dom, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>219</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>221</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            executor.schedule(this, domObj.getCacheMillis(), TimeUnit.MILLISECONDS);</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>223</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            lastRefTime = domObj.getLastRefTime();</pre></td>
    </tr>
    <tr>
      <td class='line'>224</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>225</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>226</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
